22 template <class T
> string
toStr(const T
&x
){ stringstream s
; s
<< x
; return s
.str(); }
23 template <class T
> int toInt(const T
&x
){ stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
25 #define For(i, a, b) for (int i=(a); i<(b); ++i)
26 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
27 #define D(x) cout << #x " = " << (x) << endl
29 const int MOD
= 1000000007;
32 typedef vector
< vector
<long long> > matrix
;
37 matrix
mul(const matrix
&A
, const matrix
&B
){
41 matrix
C(p
, vector
<long long>(r
, 0));
42 for (int i
=0; i
<p
; ++i
){
43 for (int j
=0; j
<r
; ++j
){
45 for (int k
=0; k
<q
; ++k
){
46 C
[i
][j
] += (A
[i
][k
] * B
[k
][j
]) % MOD
;
56 matrix
exp(const matrix
&A
, int e
){
59 matrix
C(n
, vector
<long long>(n
, 0));
60 for (int i
=0; i
<n
; ++i
){
70 matrix B
= exp(A
, e
/ 2);
82 for (int Caso
=1; Caso
<=Casos
; ++Caso
){
84 if (!(cin
>> n
>> m
>> k
>> d
)) break;
85 for (int i
=0; i
<n
; ++i
){
91 int u
, v
; cin
>> u
>> v
;
92 g
[u
].push_back(v
), g
[v
].push_back(u
);
95 //find day of sum for each node
100 int u
= q
.front(); q
.pop();
110 matrix
odd(n
, vector
<long long>(n
));
111 matrix
even(n
, vector
<long long>(n
));
112 //find odd/even matrices
113 for (int j
=0; j
<n
; ++j
){
114 for (int i
=0; i
<n
; ++i
){
115 odd
[i
][j
] = even
[i
][j
] = 0;
125 even
[j
][j
] = odd
[j
][j
] = 1;
128 //D("odd"); For(i, 0, n){ For(j, 0, n) printf("%d ", odd[i][j]); printf("\n"); }
130 //D("even"); For(i, 0, n){ For(j, 0, n) printf("%d ", even[i][j]); printf("\n"); }
132 matrix C
= mul(odd
, even
);
138 //D("C"); For(i, 0, n){ For(j, 0, n) printf("%d ", C[i][j]); printf("\n"); }
140 matrix
ans(1, vector
<long long>(n
));
142 for (int j
=0; j
<n
; ++j
){
149 printf("Case %d:", Caso
);
150 for (int j
=0; j
<n
; ++j
){
151 printf(" %d",(int) C
[0][j
]);